home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Voyeur 1.1.1
/
Voyeur ƒ
/
MSG Shell ƒ
/
msg menus.c
< prev
next >
Wrap
Text File
|
1994-02-27
|
6KB
|
285 lines
/**********************************************************************\
File: msg menus.c
Purpose: This module handles menu selections.
Voyeur -- a no-frills file viewer
Copyright ©1993-4, Mark Pilgrim
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in a file named "GNU General Public License".
If not, write to the Free Software Foundation, 675 Mass Ave,
Cambridge, MA 02139, USA.
\**********************************************************************/
#include "msg graphics.h"
#include "msg menus.h"
#include "msg prefs.h"
#include "msg environment.h"
#include "msg help.h"
#include "v.h"
#include "v meat.h"
#include "v find.h"
#include "program globals.h"
#include "v error.h"
#include "v type creator.h"
#include "v window maintenance.h"
MenuHandle gAppleMenu;
MenuHandle gFileMenu;
MenuHandle gEditMenu;
MenuHandle gViewMenu;
MenuHandle gOptionsMenu;
MenuHandle gHelpMenu;
MenuHandle gWindowMenu;
void AdjustMenus(void)
{
WindowPeek theWindow;
int kind;
int i;
int numWindows;
theWindow = (WindowPeek)FrontWindow();
kind = theWindow ? theWindow->windowKind : 0;
if (!gInProgress)
{
EnableItem(gAppleMenu, aboutItem);
EnableItem(gAppleMenu, aboutMSGItem);
EnableItem(gAppleMenu, helpItem);
if(kind < 0) EnableItem(gEditMenu, 0);
else DisableItem(gEditMenu, 0);
EnableItem(gFileMenu, 0);
EnableItem(gViewMenu, 0);
EnableItem(gOptionsMenu, 0);
EnableItem(gWindowMenu, 0);
if (theWindow)
{
EnableItem(gFileMenu, closeItem);
EnableItem(gFileMenu, closeAllItem);
}
else
{
DisableItem(gFileMenu, closeItem);
DisableItem(gFileMenu, closeAllItem);
}
numWindows=CountProgramWindows();
if (numWindows>0)
{
if (numWindows==MAX_WINDOWS)
DisableItem(gFileMenu, openItem);
else
EnableItem(gFileMenu, openItem);
EnableItem(gViewMenu, 0);
EnableItem(gOptionsMenu, 0);
CheckItem(gViewMenu, dataForkItem, (gWhichFork[gWhichFile]==0));
CheckItem(gViewMenu, resourceForkItem, (gWhichFork[gWhichFile]==1));
if ((gFindHex ? gFindHexStringInAscii[0] : gFindString[0])==0x00)
DisableItem(gOptionsMenu, findAgainItem);
else
EnableItem(gOptionsMenu, findAgainItem);
}
else
{
EnableItem(gFileMenu, openItem);
CheckItem(gViewMenu, dataForkItem, FALSE);
CheckItem(gViewMenu, resourceForkItem, FALSE);
DisableItem(gViewMenu, 0);
DisableItem(gOptionsMenu, 0);
}
if (gWindowMenu!=0L)
for (i=1; i<=numWindows; i++)
CheckItem(gWindowMenu, i, FrontWindow()==GetProgramWindowFromIndex(i-1));
}
else
{
DisableItem(gAppleMenu, aboutItem);
DisableItem(gAppleMenu, aboutMSGItem);
DisableItem(gAppleMenu, helpItem);
DisableItem(gFileMenu, 0);
DisableItem(gViewMenu, 0);
DisableItem(gOptionsMenu, 0);
DisableItem(gWindowMenu, 0);
}
}
void HandleMenu(long mSelect)
{
int menuID = HiWord(mSelect);
int menuItem = LoWord(mSelect);
switch (menuID)
{
case appleMenu:
HandleAppleMenu(menuItem);
break;
case fileMenu:
HandleFileMenu(menuItem);
break;
case editMenu:
HandleEditMenu(menuItem);
break;
case viewMenu:
HandleViewMenu(menuItem);
break;
case optionsMenu:
HandleOptionsMenu(menuItem);
break;
case helpMenu:
HandleHelpMenu(menuItem);
break;
case windowMenu:
HandleWindowMenu(menuItem);
break;
}
}
void HandleAppleMenu(int menuItem)
{
GrafPtr savePort;
Str255 name;
if(menuItem == 1)
OpenTheWindow(kAbout);
if (menuItem == 2)
OpenTheWindow(kAboutMSG);
else if(menuItem > 4)
{
GetPort(&savePort);
GetItem(gAppleMenu, menuItem, name);
OpenDeskAcc(name);
SetPort(savePort);
}
}
void DoTheCloseThing(WindowPtr theWindow)
{
Boolean gotone;
int i;
if (IsProgramWindow(theWindow))
CloseProgramWindow(GetProgramWindowIndex(theWindow));
else
{
gotone=FALSE;
for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
gotone=(theWindow==gTheWindow[i]);
if (gotone)
CloseTheWindow(i-1);
else
DisposeWindow(theWindow);
}
AdjustMenus();
}
void HandleFileMenu(int menuItem)
{
switch (menuItem)
{
case openItem:
HandleError(NewEditWindow());
break;
case closeItem:
DoTheCloseThing(FrontWindow());
break;
case closeAllItem:
while (FrontWindow()!=0L)
DoTheCloseThing(FrontWindow());
break;
case quitItem:
gDone = TRUE;
break;
}
}
void HandleEditMenu(int menuItem)
{
if ((menuItem>0) && (menuItem!=2))
if(!SystemEdit(menuItem - 1))
if(menuItem == undoItem)
ProgramUndo();
}
void HandleViewMenu(int menuItem)
{
switch (menuItem)
{
case dataForkItem:
DoDataFork();
break;
case resourceForkItem:
DoResourceFork();
break;
case forwardItem:
GoForward();
break;
case backItem:
GoBack();
break;
case beginningItem:
GoBeginning();
break;
case endItem:
GoEnd();
break;
case offsetItem:
GoOffset();
break;
}
}
void HandleOptionsMenu(int menuItem)
{
switch (menuItem)
{
case typeCreatorItem:
ChangeTypeCreator();
break;
case eofItem:
ChangeEOF();
break;
case findItem:
DoFind(FALSE);
break;
case findHexItem:
DoFind(TRUE);
break;
case findAgainItem:
DoFindAgain();
break;
}
}
void HandleHelpMenu(int menuItem)
{
gWhichHelp=menuItem;
UpdateHelpWindow();
}
void HandleWindowMenu(int menuItem)
{
SelectProgramWindow(gTheWindow[kMainWindow+menuItem-1]);
}